package com.appfahrt.persistence.obj2.dao.generated;

import java.util.ArrayList;
import java.sql.SQLException;

//TODO:ggf wegfallen
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

import com.appfahrt.persistence.obj2.AppFahrtDbDefaultDao;
import com.appfahrt.persistence.obj2.dbo.AdresseDbo;
import com.appfahrt.persistence.obj2.dbo.LoginDbo;
import com.appfahrt.persistence.obj2.utility.ReflectionUtility;
import com.appfahrt.persistence.obj2.utility.Utility;

/**
 * This Class is automatically generated.<br><br>
 *
 * <br><b>DON'T MODIFY THIS FILE</b><br><br>
 *
 * Generated: Sun May 22 22:20:17 CEST 2011
 */
public class AdresseGeneratedDao extends AppFahrtDbDefaultDao {

	private References references = new References();
	private static final String TAG = AdresseGeneratedDao.class.getSimpleName();


	/**
	 * Value Holder for the finder methods 
	 * by references.
	 */
	public class References {
	
	}

	/**
	 * Constructor.
	 */
	public AdresseGeneratedDao(Context pContext) {
		super(pContext);
	}
	
	/**
	 * Returns the finder methods
	 * by references
	 */
	public References getReferences() {
		return this.references;
	}
/*
	public AdresseDbo findWithPrimaryKey() throws SQLException {
		AdresseDbo result = null;
		findBySqlReturnObject(
			AdresseDbo.class, 
			"SELECT * FROM ${schema}.adresse WHERE ", 
			new Object[]{});
		return result;
	}
	@SuppressWarnings("unchecked")
	public ArrayList<AdresseDbo> findBySqlReturnArrayList(String sql, Object[] param) throws SQLException {
		ArrayList<AdresseDbo> result = null;
		result = findBySqlReturnArrayList(
			AdresseDbo.class, 
			sql, 
			param);
		return result;
	}
*/	
	/**
	 * Execute the given SQL Statement<br>
	 * @param sql
	 * @param param
	 * @return
	 * @throws SQLException
	 */
	public AdresseDbo findBySqlReturnObject(String pSql, String[] pParam) throws SQLException {
		AdresseDbo aResult = null;
		Cursor aValue =  findObject(pSql,pParam);
		if (aValue != null && aValue.moveToFirst() != false && aValue.getCount() == 1) {
			String [] aColumns = AdresseDbo.COLUMNS;
			aResult = new AdresseDbo();
			for(int i = 0; i < aColumns.length; i++){
				Object [] aParameter = new Object[] {aValue.getString(aValue.getColumnIndex(aColumns[i]))};
				String aMethode = Utility.createJavaNameFromFieldName(false,aColumns[i]);
				ReflectionUtility.executeMethod(aResult, aMethode, aParameter);
			}
		}
		return aResult;
	}
	
	public AdresseDbo findByAdresse(String pOrt){
		AdresseDbo aResult = null;
		String aSql = "SELECT * FROM Adresse WHERE "+AdresseDbo.ort+"=?";
		String [] aParam = new String []{String.valueOf(pOrt)};
		Log.e(TAG,"findByEmail: ["+pOrt+"]");
		Cursor aValue =  findObject(aSql,aParam);
		if (aValue != null && aValue.moveToFirst() != false && aValue.getCount() == 1) {
			aResult = new AdresseDbo();
			if(aValue.getString(aValue.getColumnIndex(AdresseDbo.hausnummer))!=null){
				Log.e(TAG,"aValue.getString(hausnummer)"+aValue.getString(aValue.getColumnIndex(AdresseDbo.hausnummer)));
				aResult.setHausnummer(aValue.getString(aValue.getColumnIndex(AdresseDbo.hausnummer)));
			}
			if(aValue.getString(aValue.getColumnIndex(AdresseDbo.id))!=null){
				Log.e(TAG,"aValue.getString(id)"+aValue.getString(aValue.getColumnIndex(AdresseDbo.id)));
				aResult.setId(Long.valueOf(aValue.getString(aValue.getColumnIndex(AdresseDbo.id))));
			}
			if(aValue.getString(aValue.getColumnIndex(AdresseDbo.ort))!=null){
				Log.e(TAG,"aValue.getString(ort)"+aValue.getString(aValue.getColumnIndex(AdresseDbo.ort)));
				aResult.setOrt(aValue.getString(aValue.getColumnIndex(AdresseDbo.ort)));
			}
			if(aValue.getString(aValue.getColumnIndex(AdresseDbo.plz))!=null){
				Log.e(TAG,"aValue.getString(plz)"+aValue.getString(aValue.getColumnIndex(AdresseDbo.plz)));
				aResult.setPlz(Long.valueOf(aValue.getString(aValue.getColumnIndex(AdresseDbo.plz))));
			}
			if(aValue.getString(aValue.getColumnIndex(AdresseDbo.strasse))!=null){
				Log.e(TAG,"aValue.getString(strasse)"+aValue.getString(aValue.getColumnIndex(AdresseDbo.strasse)));
				aResult.setStrasse(aValue.getString(aValue.getColumnIndex(AdresseDbo.strasse)));
			}
		}
		if(aValue!=null){
			aValue.close();
		}
		return aResult;
	}

// FINDER BY INDEX

// Equals


// GreaterThan, GreaterEqualThan, LessThan, LessOrEqualThan

}